//
//  SKStatus.swift
//  WeiboProjectYL
//
//  Created by yanli on 16/7/12.
//  Copyright © 2016年 mountainPassCell. All rights reserved.
//

import UIKit
// 微博模型数组
class SKStatus: NSObject {
    //  发布微博时间
    var created_at: String?
    //  微博id
    var id: Int64 = 0
    //  微博内容
    var text: String?
    //  来源
    var source: String?
    
    //  关注用户对象
    var user: SKUser?
    
    
    //  转发数
    var reposts_count: Int = 0
    //  评论数
    var comments_count: Int = 0
    //  表态数(赞)
    var attitudes_count: Int = 0
    //  转发微博对象
    var retweeted_status: SKStatus?
    
    //  配图信息
    var pic_urls: [SKStatusPictureInfo]?
    
    
    //  kvc构造函数
    init(dic: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
        
    }
    
    // kvc 赋值调用
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            
            guard let dic = value as? [String: AnyObject] else {
                return
            }
            //  代码执行到此,一定是我们想要的字典格式
            user = SKUser(dic: dic)
            
        } else if key == "retweeted_status" {
            
            guard let dic = value as? [String: AnyObject] else {
                return
            }
            
            //  代码执行到此,一定是我们想要的字典格式
            //  retweeted_status  转发微博对象
            retweeted_status = SKStatus(dic: dic)
            
        } else if key == "pic_urls" {
            // [[String: AnyObject]] 字典数据
            guard let dicArray = value as? [[String: AnyObject]] else {
                return
            }
            //  代码执行到此我们的字典数组一定有值
            var tempArray = [SKStatusPictureInfo]()
            for dic in dicArray {
                let pictureInfo = SKStatusPictureInfo(dic: dic)
                tempArray.append(pictureInfo)
            }
            
            //  设置自定义属性
            pic_urls = tempArray
            
            
        }else {
            super.setValue(value, forKey: key)
        }
        
    }
    
    
    
    
    //  防止字段比匹配,导致崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }

}
